<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html 
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	lang="en">
	
	<ui:decorate template="/WEB-INF/facelets/faceletListar.xhtml">
		<ui:define name="form">
			<h:form>
				<p:outputPanel autoUpdate="true" id="painelAjax">
					
					<p:panel id="painelListar" rendered="#{UFMB.modoListar}">
					
						<h:messages id="messages" globalOnly="true"
		                	style="border: 1px solid #999999;background-color:#ffffee;padding:6px;font-weight:bold"
		                	errorStyle="color:#ff0000;font-weight:bold" layout="table"/>
					
						<p:commandButton action="#{UFMB.criar}" value="Novo &raquo;"></p:commandButton>
						<p></p>
								
						<p:dataTable 
							value="#{UFMB.lista}" 
							var="obj" 
							selectionMode="single" 
							selection="#{UFMB.entidade}"
							paginator="true"
							rows="10"
							rowKey="#{obj.id}"
							widgetVar="tabela"
							emptyMessage="Nenhum registro encontrado."
							rowIndexVar="indice">
									
							<p:ajax event="rowSelect" listener="#{UFMB.selecionarEditar}"></p:ajax>
							<p:column>
								<f:facet name="header">
							    	<h:outputText value="Nº" />
							   	</f:facet>
							    <div align="center">
							    	<h:outputText value="#{indice + 1}" />
							    </div>
							</p:column>
							
							<p:column>
								<f:facet name="header">
							    	<h:outputText value="Nome" />
							    </f:facet>
							    <h:outputText value="#{obj.nome}" />
							</p:column>
							        
							<p:column>
								<f:facet name="header">
							    	<h:outputText value="Sigla" />
							    </f:facet>
								<div align="center">					           
							    	<h:outputText value="#{obj.sigla}" />
							    </div>
							</p:column>
						</p:dataTable>
					</p:panel>
					
					<p:panel id="painelEditar" rendered="#{UFMB.modoEditar}">
						<p:messages id="mensagens"></p:messages>	
					
						<fieldset>
							<legend>Cadastro de Unidades Federativas</legend>
						
							<div class="row-fluid">
								<div class="span6">
									<div class="control-group">	
										<h:outputLabel value="Nome:" for="nome" styleClass="control-label"/>
										<p:inputText id="nome" value="#{UFMB.entidade.nome}" maxlength="30"/>
									</div>
								</div>
								<div class="span6">
									<div class="control-group">	
										<h:outputLabel value="Sigla:" for="sigla" styleClass="control-label"/>
										<p:inputText id="sigla" value="#{UFMB.entidade.sigla}" maxlength="2"/>
									</div>
								</div>
							</div>
								
							<div class="control-group">
								<p:commandButton 
									value="Gravar" 
									action="#{UFMB.gravar}"
									update="mensagens"/>
								
								<span></span>
								
								<p:commandButton 
									value="Voltar" 
									action="#{UFMB.voltar}"
									immediate="true"/>
								
								<span></span>
								
								<p:commandButton 
									value="Excluir" 
									action="#{UFMB.excluir}"
									rendered="#{UFMB.exibirExcluir}"
									onclick="confirmation.show()" 
									type="button"/>
									
								<p:confirmDialog 
									id="confirmDialog" 
									message="Confimar a exclusão do registro?"  
							    	header="Confirmação!" 
							    	severity="alert" 
							    	widgetVar="confirmation">  
							                  
									<p:commandButton 
							   			id="confirm" 
							   			value="Sim" 
							   			oncomplete="confirmation.hide()"  
							    		action="#{UFMB.excluir}"/>  
							        
									<p:commandButton 
							  			id="decline" 
							   			value="Não" 
							   			onclick="confirmation.hide()" 
							   			type="button" />   
							                  
								</p:confirmDialog>
							</div>
						</fieldset>
					</p:panel>
				</p:outputPanel>
			</h:form>
		</ui:define>
	</ui:decorate>	
</html>